package com.asiainfo.dao;
/*
 * 
 * 排课数据操作类
 */
import java.sql.ResultSet;
import java.sql.SQLException;
import com.asiainfo.bean.Schedule;
import com.asiainfo.database.JdbcTemplete;
import com.asiainfo.database.ResultSetHandler;

public class Schedule_Dao {
	//增加排课
	public int addSchedule(Schedule schedule){
		JdbcTemplete jt = new JdbcTemplete();
		String sql = "insert into schedule(schedule_date,schedule_course,schedule_coach,schedule_num,schedule_count) values (?,?,?,?,?)";
		return jt.update(sql, schedule.getSchedule_date(),schedule.getSchedule_course(),schedule.getSchedule_coach(),schedule.getSchedule_num(),schedule.getSchedule_count());
	}
	//查找某个时间点的排课
	public Schedule getscheduleByTime(int time){
		JdbcTemplete jt = new JdbcTemplete();
		String sql = "select schedule_date,schedule_course,schedule_coach,schedule_num,schedule_count,schedule_id from schedule where schedule_date=?";
		Schedule schedule = (Schedule) jt.quary(sql, new ResultSetHandler() {
			public Object doHandler(ResultSet rs) throws SQLException {
				Schedule schedule = null;
				if (rs.next()) {
					schedule = new Schedule();
					schedule.setSchedule_date(rs.getInt(1));
					schedule.setSchedule_course(rs.getInt(2));
					schedule.setSchedule_coach(rs.getInt(3));
					schedule.setSchedule_num(rs.getInt(4));
					schedule.setSchedule_count(rs.getInt(5));
					schedule.setSchedule_id(rs.getInt(6));
				}
				return schedule;
			}
		}, time);
		return schedule;
	}
}
